package cn.changeforyou.web.cloud.auth.service.impl;

import cn.changeforyou.web.cloud.auth.entity.User;
import cn.changeforyou.web.cloud.auth.entity.vos.UserVO;
import cn.changeforyou.web.cloud.auth.mapper.UserMapper;
import cn.changeforyou.web.cloud.auth.service.UserService;
import cn.changeforyou.web.cloud.auth.util.AuthUtil;
import cn.changeforyou.web.cloud.webBase.utils.bean.BeanCopierUtil;
import cn.changeforyou.web.plugin.page.MybatisPlusPageUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 *
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
        implements UserService {

    @Override
    public Page queryUsersByPage() {
        Page<User> pageInfo = MybatisPlusPageUtil.getPageInfo(this.getClass());
        return this.page(pageInfo);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public User addEntity(User user) {
        user.setPassword(AuthUtil.encryptPassword(user.getPassword()));
        this.save(user);
        return user;
    }

    @Override
    public User selectByIdWithResultTypeXml(Integer id) {
        return getBaseMapper().selectByIdWithResultTypeXml(id);
    }

    @Override
    public UserVO selectUserVO(Integer id) {
        User user = this.getById(id);
        if (null == user) {
            return null;
        } else {
            UserVO userVO = new UserVO();
            BeanCopierUtil.copy(user, userVO);
            return userVO;
        }
    }
}




